<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ page import="com.jdbc.tool.*"%>   
 <%@ page import="java.sql.*" %>
 <%@page import="java.util.Date"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>My JSP 'Geren.jsp' starting page</title>

	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<script type="text/javascript">
		function checknum1() { 

	if (!checkIdcard(formname.userCarid.value)){
		return false;
	}
	if (!checkid(formname.userId.value)){
		return false;
	}
	return true;
  }   
  /*
下面的弄好后。就可以改函数了，函数可以根据下面的用，框架是
function （函数名）(){
    var temp= document.getElementById("（下面的id名）");
	var partten = /^((\(\d{3}\))|(\d{3}\-))?13[0-9]\d{8}|15[0-9]\d{8}|189\d{8}$/;---（正则表达式）
	if(temp.value!=""){
	if(!partten.test(temp.value)){
	alert('提示:请输入有效的mobile！');---（不同的提示语）
	（下面的id名）.focus();
		return false ;
	}else{
		return false ;
	}
}
}
*/
  

  //checkaddress()
        function checkaddress(){
    var temp= document.getElementById("address");
	var partten = /^[\u4E00-\u9FA5]+$/;
	if(temp.value!=""){
	if(!partten.test(temp.value)){
	alert('提示:请输入有效的地址！');
	address.focus();
		return false ;
	}else{
		return false ;
	}
}
		return true;
	
}
  //checkphone()
      function checkphone(){
    var temp= document.getElementById("phone");
	var partten = /^((\(\d{3}\))|(\d{3}\-))?13[0-9]\d{8}|15[0-9]\d{8}|189\d{8}$/;
	if(temp.value!=""){
	if(!partten.test(temp.value)){
	alert('提示:请输入有效的电话！');
	phone.focus();
		return false ;
	}else{
		return false ;
	}
}
		return true;
	
}
  //checkemail()
    function checkemail(){
    var temp= document.getElementById("email");
	var partten = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
	if(temp.value!=""){
	if(!partten.test(temp.value)){
	alert('提示:请输入有效的email！');
	email.focus();
		return false ;
	}else{
		return false ;
	}
}
		return true;
	
}
  
  //验证name
  function checkname(){
    var temp= document.getElementById("name");
	var partten = /^[\u4E00-\u9FA5]+$/;
	if(temp.value!=""){
	if(!partten.test(temp.value)){
	alert('提示:请输入有效的name，只能是汉字！');
	name.focus();
		return false ;
	}else{
		return false ;
	}
}
		return true;
	
}
  //验证pass
function checkpass(){
    var temp= document.getElementById("pass");
	var partten = /^[A-Za-z0-9]+$/;
	if(temp.value!=""){
	if(!partten.test(temp.value)){
	alert('提示:请输入有效的pass,只能是数字和字母！');
	pass.focus();
		return false ;
	}else{
		return false ;
	}
}
		return true;
	
}
  //验证id
  function checkid(num){
	num = num.toUpperCase();
    if (!(/^[a-zA-Z]+$/.test(num)))
    {
        alert('输入的id必须是字母');
        return false;
    }
    	return true;
    
  }
		
  //验证身份证。
 function checkIdcard(num){
    num = num.toUpperCase();
    if (!(/(^\d{15}$)|(^\d{17}([0-9]|X)$)/.test(num)))
    {
        alert('输入的身份证号长度不对，或者号码不符合规定！\n15位号码应全为数字，18位号码末位可以为数字或X。');
        return false;
    }
 
    var len, re;
    len = num.length;
    if (len == 15)
    {
        re = new RegExp(/^(\d{6})(\d{2})(\d{2})(\d{2})(\d{3})$/);
        var arrSplit = num.match(re);
 
       
        var dtmBirth = new Date('19' + arrSplit[2] + '/' + arrSplit[3] + '/' + arrSplit[4]);
        var bGoodDay;
        bGoodDay = (dtmBirth.getYear() == Number(arrSplit[2])) && ((dtmBirth.getMonth() + 1) == Number(arrSplit[3])) && (dtmBirth.getDate() == Number(arrSplit[4]));
        if (!bGoodDay)
        {
            alert('输入的身份证号里出生日期不对！');
            return false;
        }
        else
        {
              
                var arrInt = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);
                var arrCh = new Array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2');
                var nTemp = 0, i;
                num = num.substr(0, 6) + '19' + num.substr(6, num.length - 6);
                for(i = 0; i < 17; i ++)
                {
                    nTemp += num.substr(i, 1) * arrInt[i];
                }
                num += arrCh[nTemp % 11];
                return true;
        }
    }
    if (len == 18)
    {
        re = new RegExp(/^(\d{6})(\d{4})(\d{2})(\d{2})(\d{3})([0-9]|X)$/);
        var arrSplit = num.match(re);
 
        //检查生日日期是否正确
        var dtmBirth = new Date(arrSplit[2] + "/" + arrSplit[3] + "/" + arrSplit[4]);
        var bGoodDay;
        bGoodDay = (dtmBirth.getFullYear() == Number(arrSplit[2])) && ((dtmBirth.getMonth() + 1) == Number(arrSplit[3])) && (dtmBirth.getDate() == Number(arrSplit[4]));
        if (!bGoodDay)
        {
            alert('输入的身份证号里出生日期不对！');
            return false;
        }
    else
    {
        //检验18位身份证的校验码是否正确。
        //校验位按照ISO 7064:1983.MOD 11-2的规定生成，X可以认为是数字10。
        var valnum;
        var arrInt = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);
        var arrCh = new Array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2');
        var nTemp = 0, i;
        for(i = 0; i < 17; i ++)
        {
            nTemp += num.substr(i, 1) * arrInt[i];
        }
        valnum = arrCh[nTemp % 11];
        if (valnum != num.substr(17, 1))
        {
            alert('18位身份证的校验码不正确！应该为：' + valnum);
            return false;
        }
        return true;
    }
    }
    return false;
}
	</script>
   <% 
   String userid=(String) session.getAttribute("id");
   Connection conn = DBLianjie.getconn();
   Statement stm = conn.createStatement();
   ResultSet rs = stm.executeQuery("select * from emai_user where e_user_id='"+userid+"'");
   rs.next();
   Date data =rs.getDate("E_BRITHDAY");
   int y=data.getYear();
   int m=data.getMonth()+1;
   int r=data.getDate();
   %>
   
   <style>
   body{
   text-align: center;
   }
   .list{
      width:100%;
      border-top:2px solid #dfc9b2;
      border-bottom:2px solid #dfc9b2;
    }
    .list th{
    width:100px;
    background:#f7f4eb;
    color:#8a7152;
    }
    #sub{
    width:55px;
    height:50px;
    border:none;
    background:transparent url("xiougai1.png") no-repeat;
    }
   </style>
  </head>
  
  <body>
    <form action="./UserDao" name="formname" method="post">
    <div class="list">
    <table>
    <tr>
  <th>用户ID：</th><td><input type="text" name="userId" value="<%=rs.getString("e_user_id")%>"></td>
  <th>用户姓名：</th><td><input type="text" id="name" name="username" value="<%=rs.getString("e_user_name")%>" onblur="checkname();"></td>
  </tr>
  <tr>
    <th>用户密码：</th><td><input type="text" id="pass" name="userpass" value="<%=rs.getString("E_PASSWORD")%>" onblur="checkpass();"></td>
    <th>用户性别：</th>
    <%if("男".equals(rs.getString("e_sex").trim())){%>
						<td><input name="sex" type="radio" value="男" checked="checked" />男
                            <input type="radio" name="sex" value="女" />女</td>
                            <%}else{%>
                        <td><input name="sex" type="radio" value="男"  />男
                            <input type="radio" name="sex" value="女" checked="checked"/>女</td>
                            <% }%>
    </tr>  
       <tr>
   <th> 用户生日：</th>
   						<td>
							<select name="birthyear">
							<% for(int i=90;i<=99;i++){%>
							<% if(y==i){%>
								<option value="<%=i%>" selected="selected"><%=1900+i%></option>
								<%}else{%>
								<option value="<%=i%>"><%=1900+i%></option>
								<% }
							}%>
							</select>年
							<select name="birthmonth">
							<% for(int i=1;i<=12;i++){%>
							   <% if(m==i){%>
								<option value="<%=i%>" selected="selected"><%=i%></option>
								<%}else{%>
								<option value="<%=i%>"><%=i%></option>
								<% }}%>
							</select>月
							<select name="birthday">
								<% for(int i=1;i<=31;i++){%>
							   <% if(r==i){%>
								<option value="<%=i%>" selected="selected"><%=i%></option>
								<%}else{%>
								<option value="<%=i%>"><%=i%></option>
								<% }
							   }%>
							</select>日
						</td>

    <th>身份证  ：</th><td><input type="text" name="userCarid" value="<%=rs.getString("E_IDENTITY_CODE")%>"></td>
    </tr>
    <tr>
    <th>用户邮箱：</th><td><input type="text" id="email" name="email" value="<%=rs.getString("e_emial")%>" onblur="checkemail();"></td>
    <th>用户电话：</th><td><input type="text" id="phone" name="pone" value="<%=rs.getString("e_mobile")%>" onblur="checkphone();"></td>
    </tr>
    <tr>
    <th> 用户地址：</th><td><input type="text" id="address" name="addres" value="<%=rs.getString("E_ADDRESS")%>" onblur="checkaddress();"></td>
   <th> 用户级别：</th>
   <%if("1".equals(rs.getString("E_STATUS"))){%>
   <td><input type="radio" name="jibie" value="1" checked="checked">管理员
   <input type="radio" name="jibie" value="2">普通用户
   </td>
   <%}else{%>
   <td><input type="radio" name="jibie" value="1" >管理员
   <input type="radio" name="jibie" value="2" checked="checked">普通用户
   </td>
   <% }%>
   </tr>
   <tr>
    <th>用户备注：</th><td><input type="text" name="beizhu" value="<%=rs.getString("E_LJ")%>"></td>
    </tr>
    </table>
    </div>
    
    <input type="submit" value="" name="submit" id="sub" onclick="return checknum1()">
    
    </form>
  </body>
</html>
